
#region Using directives

using System;
using System.Collections;
using System.IO;
using Microsoft.WindowsMobile.PocketOutlook;


#endregion
/** 
COPYRIGHT (C) 2008 Piyusha Desai. All Rights Reserved.
* Read Licence.txt before using this application.
*/
namespace SmsBuddy
{
   // just a collection of group
    public class GroupCollection: ICollection, IList
    {
  
        ArrayList list = new ArrayList();

        public int Count
        {
            get { return list.Count; }
        }

        public Group this[int index]
        {
            get
            {
                return (Group)list[index];
            }
            set
            {
                throw new Exception("The method or operation is not implemented.");
            }
        }


        public GroupCollection()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public int Add(Group group)
        {
            int id = FindNextId();
            group.Id = id;
            return list.Add(group);
        }

        public void Remove(Group group)
        {
            list.Remove(group);
        }

      
        private int FindNextId()
        {
            int index;
            for (index = 0; index < list.Count && this[index].Id == index; index++)
            {
                
            }

            return index;
        }


        //Write in file to save it.
          public void Save(string filename)
        {
            StreamWriter sw = new StreamWriter(filename);
            foreach (Group group in list)
            {
                group.Save(sw);
            }
            sw.Close();
        }

        #region ICollection Members
        void ICollection.CopyTo(Array array, int index)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        int ICollection.Count
        {
            get { return list.Count; }
        }

        bool ICollection.IsSynchronized
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        object ICollection.SyncRoot
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        #endregion

        #region IEnumerable Members

        IEnumerator IEnumerable.GetEnumerator()
        {
            return list.GetEnumerator();
        }

        #endregion


        #region IList Members

        int IList.Add(object value)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        void IList.Clear()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        bool IList.Contains(object value)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        int IList.IndexOf(object value)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        void IList.Insert(int index, object value)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        bool IList.IsFixedSize
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        bool IList.IsReadOnly
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        void IList.Remove(object value)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        void IList.RemoveAt(int index)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        object IList.this[int index]
        {
            get
            {
                throw new Exception("The method or operation is not implemented.");
            }
            set
            {
                throw new Exception("The method or operation is not implemented.");
            }
        }

        #endregion
    }
}
